<?php 

namespace app\admin\event;

use app\common\model\Shop as ShopModel;
use app\common\utils\JsonService;

class ShopEvent{

    /*
    * 店铺列表
    */
    public static function shopList(){
        $params = array_filter(request()->param());
        $page = ! empty($params['page']) && $params['page'] >= 1 ? $params['page'] : 1;
        $where = [];
        if($shop_id = isset($params['shop_id'])){
                    $where[] = [['shop_id','=',$params['shop_id']]];
            }
            if($shop_name = isset($params['shop_name'])){
                    $where[] = [['shop_name','like',"%{$params['shop_name']}%"]];
            }
            if($shop_type_id = isset($params['shop_type_id'])){
                    $where[] = [['shop_type_id','like',"%{$params['shop_type_id']}%"]];
            }
            if($shop_type_name = isset($params['shop_type_name'])){
                    $where[] = [['shop_type_name','like',"%{$params['shop_type_name']}%"]];
            }
            if($member_id = isset($params['member_id'])){
                    $where[] = [['member_id','like',"%{$params['member_id']}%"]];
            }
            if($shop_group_id = isset($params['shop_group_id'])){
                    $where[] = [['shop_group_id','like',"%{$params['shop_group_id']}%"]];
            }
            if($shop_group_name = isset($params['shop_group_name'])){
                    $where[] = [['shop_group_name','like',"%{$params['shop_group_name']}%"]];
            }
            if($company_name = isset($params['company_name'])){
                    $where[] = [['company_name','like',"%{$params['company_name']}%"]];
            }
            if($province_id = isset($params['province_id'])){
                    $where[] = [['province_id','like',"%{$params['province_id']}%"]];
            }
            if($city_id = isset($params['city_id'])){
                    $where[] = [['city_id','like',"%{$params['city_id']}%"]];
            }
            if($district_id = isset($params['district_id'])){
                    $where[] = [['district_id','like',"%{$params['district_id']}%"]];
            }
            if($address_detail = isset($params['address_detail'])){
                    $where[] = [['address_detail','like',"%{$params['address_detail']}%"]];
            }
            if($shop_zip = isset($params['shop_zip'])){
                    $where[] = [['shop_zip','like',"%{$params['shop_zip']}%"]];
            }
            if($shop_close_info = isset($params['shop_close_info'])){
                    $where[] = [['shop_close_info','like',"%{$params['shop_close_info']}%"]];
            }
            if($shop_sort = isset($params['shop_sort'])){
                    $where[] = [['shop_sort','like',"%{$params['shop_sort']}%"]];
            }
            if($shop_banner = isset($params['shop_banner'])){
                    $where[] = [['shop_banner','like',"%{$params['shop_banner']}%"]];
            }
            if($shop_avatar = isset($params['shop_avatar'])){
                    $where[] = [['shop_avatar','like',"%{$params['shop_avatar']}%"]];
            }
            if($shop_keywords = isset($params['shop_keywords'])){
                    $where[] = [['shop_keywords','like',"%{$params['shop_keywords']}%"]];
            }
            if($shop_description = isset($params['shop_description'])){
                    $where[] = [['shop_description','like',"%{$params['shop_description']}%"]];
            }
            if($shop_qq = isset($params['shop_qq'])){
                    $where[] = [['shop_qq','like',"%{$params['shop_qq']}%"]];
            }
            if($shop_ww = isset($params['shop_ww'])){
                    $where[] = [['shop_ww','like',"%{$params['shop_ww']}%"]];
            }
            if($shop_domain = isset($params['shop_domain'])){
                    $where[] = [['shop_domain','like',"%{$params['shop_domain']}%"]];
            }
            if($shop_credit = isset($params['shop_credit'])){
                    $where[] = [['shop_credit','like',"%{$params['shop_credit']}%"]];
            }
            if($shop_collect = isset($params['shop_collect'])){
                    $where[] = [['shop_collect','like',"%{$params['shop_collect']}%"]];
            }
            if($shop_stamp = isset($params['shop_stamp'])){
                    $where[] = [['shop_stamp','like',"%{$params['shop_stamp']}%"]];
            }
            if($shop_printdesc = isset($params['shop_printdesc'])){
                    $where[] = [['shop_printdesc','like',"%{$params['shop_printdesc']}%"]];
            }
            if($live_store_name = isset($params['live_store_name'])){
                    $where[] = [['live_store_name','like',"%{$params['live_store_name']}%"]];
            }
            if($live_store_address = isset($params['live_store_address'])){
                    $where[] = [['live_store_address','like',"%{$params['live_store_address']}%"]];
            }
            if($live_store_bus = isset($params['live_store_bus'])){
                    $where[] = [['live_store_bus','like',"%{$params['live_store_bus']}%"]];
            }
            if($shop_vrcode_prefix = isset($params['shop_vrcode_prefix'])){
                    $where[] = [['shop_vrcode_prefix','like',"%{$params['shop_vrcode_prefix']}%"]];
            }
            if($shop_region = isset($params['shop_region'])){
                    $where[] = [['shop_region','like',"%{$params['shop_region']}%"]];
            }
            if($recommend_uid = isset($params['recommend_uid'])){
                    $where[] = [['recommend_uid','like',"%{$params['recommend_uid']}%"]];
            }
            if($shop_qrcode = isset($params['shop_qrcode'])){
                    $where[] = [['shop_qrcode','like',"%{$params['shop_qrcode']}%"]];
            }
             $condition = [
            'where' => $where,
            'order' => ['shop_id' => 'desc'],
                'paginate' => [
                'page' => $page,
                'query' => $params,
            ],
        ];
        $shop = ShopModel::getPageAll($condition);
        return $shop;
    }


    /*
    * 新增店铺
    */
    public static function createShop($data){

        try {
            ShopModel::create($data);
        } catch (\Exception $ex) {
            return JsonService::error($ex->getMessage());
        }
        return JsonService::success();
    }

    /*
    * 更新店铺
    */
    public static function updateShop($data){

        try {
            ShopModel::updateOne($data, ['shop_id' => $data['shop_id']]);
        } catch (\Exception $ex) {
            return JsonService::error($ex->getMessage());
        }
        return JsonService::success();
    }


}

